import com.sun.corba.se.spi.activation.Server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient {
    Socket socket =null;
    String serverIP ;
    int port;
    public TcpEchoClient(String serverIP,int port) throws IOException {
        socket = new Socket(serverIP,port);
        }
        public void start(){
        Scanner scannerConsole = new Scanner(System.in);
            try(InputStream inputStream = socket.getInputStream();
                OutputStream outputStream = socket.getOutputStream()){
                System.out.print("-> ");
                String request = scannerConsole.next();
                PrintStream printStream = new PrintStream(outputStream);
                printStream.print(request);
                printStream.flush();
                Scanner scannerNetwork = new Scanner(inputStream);
                String respone = scannerNetwork.next();
                System.out.println(respone);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    public static void main(String[] args) throws IOException {
        TcpEchoClient tcpEchoClient = new TcpEchoClient("127.0.0.1",5465);
        tcpEchoClient.start();
    }
    }



